package top.igotcha.mapreduce.flowsort.mapper;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import top.igotcha.mapreduce.flowsort.bean.FlowBean;

import java.io.IOException;

/**
 * @time 2021/1/10
 * @auth Gotcha
 * @describe
 */

public class FlowSortMapper extends Mapper<LongWritable,Text, FlowBean,Text> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1.对每行数据进行字符串拆分
        String[] split = value.toString().split("\t");
        //2.获取手机号
        String phoneNum = split[0];
        //3.获取四个流量字段
        FlowBean flowBean = new FlowBean();
        flowBean.setUpFlow(Integer.parseInt(split[1]));
        flowBean.setDownFlow(Integer.parseInt(split[2]));
        flowBean.setUpCountFlow(Integer.parseInt(split[3]));
        flowBean.setDownCountFlow(Integer.parseInt(split[4]));
        //4.将k2,v2写入上下文
        context.write(flowBean,new Text(phoneNum));
    }
}
